﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using InterviewAppPhone.QuizPhoneService;
using LibQuestionIsPhone.Models;
using System;

namespace InterviewAppPhone.ViewModels
{
    public class MainViewModel : BaseViewModel, INotifyPropertyChanged
    {
        public MainViewModel()
        {
            this.Items = new ObservableCollection<TipologiaTest>();
            Items = Tipologie;
        }

        /// <summary>
        /// Raccolta per oggetti ItemViewModel.
        /// </summary>
        public ObservableCollection<TipologiaTest> Items { get; private set; }


        //private bool _isConnection;

        //public bool IsConnection
        //{
        //    get { return _isConnection; }
        //    set
        //    {
        //        _isConnection = value;
        //        OnPropertyChanged("IsConnection");
        //        OnPropertyChanged("IsAssenzaRete");
        //    }
        //}

        //public bool IsAssenzaRete
        //{
        //    get { return !IsConnection; }
        //}

        //private bool _isCalculate { get; set; }
        //public bool IsCalculate
        //{
        //    get { return _isCalculate; }
        //    set
        //    {
        //        _isCalculate = value;
        //        OnPropertyChanged("IsCalculate");
        //    }
        //}

        //private bool _isDataLoaded { get; set; }

        //public bool IsDataLoaded
        //{
        //    get { return _isDataLoaded; }
        //    private set
        //    {
        //        _isDataLoaded = value;
        //        OnPropertyChanged("IsDataLoaded");
        //    }
        //}

        /// <summary>
        /// Crea e aggiunge alcuni oggetti ItemViewModel nella raccolta di elementi.
        /// </summary>
        //public void LoadData()
        //{
        //    if (IsConnection)
        //    {
        //        IsCalculate = true;
        //        QuizPhoneService.QuizServiceClient client = new QuizServiceClient();
        //        client.GetTipologieAndDifficoltaCompleted += client_GetTipologieAndDifficoltaCompleted;
        //        client.GetTipologieAndDifficoltaAsync(new QuizPhoneService.GetTipologieAndDifficoltaRequest() { Version = 100 });
        //    }
        //}

        //private void client_GetTipologieAndDifficoltaCompleted(object sender, GetTipologieAndDifficoltaCompletedEventArgs e)
        //{
        //    try
        //    {
        //        //TODO gestire nel caso in cui il servizio non torni nulla
        //        DataFlowObject.ListTipologiaTest = new ObservableCollection<TipologiaTest>();
        //        foreach (var item in e.Result.ListTipologie)
        //        {
        //            var element = new TipologiaTest() { IDTest = item.IdTipologiaTest, NomeTest = item.Descrizione };
        //            this.Items.Add(element);
        //            DataFlowObject.ListTipologiaTest.Add(element);
        //        }
        //        DataFlowObject.ListDifficolta = new ObservableCollection<Difficolta>();
        //        foreach (var item in e.Result.ListDifficolta)
        //        {
        //            DataFlowObject.ListDifficolta.Add(new Difficolta() { IDDifficolta = item.IDDifficolta, NumMaxDomande = item.NumMaxDomande, Punteggio = item.Punteggio, TempoMaxDomande = item.TempoMaxDomande, Titolo = item.Titolo });
        //        }

        //        DataFlowObject.InfoBacheca = e.Result.InfoBacheca;
        //        DataFlowObject.Version = e.Result.Version;
        //        DataFlowObject.IsDatiCaricati = true;
        //        IsCalculate = false;

        //        IsDataLoaded = true;

        //    }
        //    catch (Exception ex)
        //    {

        //        throw;
        //    }
        //}

        public override event PropertyChangedEventHandler PropertyChanged;
        public override void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}